/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "DepositCreateDialog.h"

namespace QSThink
{

	DepositCreateDialog::DepositCreateDialog( QWidget *parent/*=0*/,Qt::WindowFlags flag/*=0*/ )
		: QDialog(parent,flag),_ui(new Ui::DepositCreateUI)
	{
		
		_ui->setupUi(this);
		

		this->setMaximumWidth(400);
		this->setMaximumHeight(160);
		this->setWindowTitle(tr("Deposit"));

		_ui->lineEditAccountBalance->setValidator(new QIntValidator(this));
		_ui->dateEdit->setCalendarPopup(true);
		QDate currentDate=QDate::currentDate();
		_ui->dateEdit->setDate(currentDate);

		//void QAbstractButton::clicked ( bool checked = false )   
		connect(_ui->buttonOK,SIGNAL(clicked(bool)),this,SLOT(OnOKClicked(bool)));
		connect(_ui->buttonCancel,SIGNAL(clicked(bool)),this,SLOT(OnCancelClicked(bool)));
		
	}

	DepositCreateDialog::~DepositCreateDialog()
	{

	}

	void DepositCreateDialog::OnOKClicked( bool checked )
	{
		if(_ui->lineEditAccountBalance->text().isEmpty()){
			QMessageBox::information(this, tr("Deposit"),
			tr("Please input your <b>balance</b. "));
			return;
		}

		QDate date=_ui->dateEdit->date();
		DepositCurrencyType currency=(DepositCurrencyType)_ui->comboCurrencyType->currentIndex();
		DepositAccountType account=(DepositAccountType)_ui->comboAccountType->currentIndex();
		bool succes=false;
		int balance=_ui->lineEditAccountBalance->text().toInt(&succes);
		if(!succes){
			balance=0;//shouldn't be
		}


		DepositInfo* info= DepositManager::getSingleton().addDeposit(date,currency,account,balance);
		OnDepositCreate(info);

		_ui->comboCurrencyType->setCurrentIndex(0);
		_ui->comboAccountType->setCurrentIndex(0);
		_ui->lineEditAccountBalance->clear();
		this->hide();
	}

	void DepositCreateDialog::OnCancelClicked( bool checked )
	{
		this->hide();
	}



}
